using System;
using Microsoft.SPOT;
using Gadgeteer.Interfaces.Temp;
using Gadgeteer.Interfaces.Fakes.Framework;

namespace Gadgeteer.Interfaces.Fakes
{
    /// <summary>
    /// Fake temprature humidity sensor.
    /// Set the delay to .2 seconds and the repeat at .5 seconds.
    /// </summary>
    public class FakeTempratureHumidity : SensorBase, ITemperatureHumidity
    {
        public double Temperature { get; set; }
        public double Humidity { get; set; }

        /// <summary>
        /// Create a fake temprature and humidity sensor with a backing thread named <paramref name="name"/>.
        /// </summary>
        public FakeTempratureHumidity(string name)
            : base(name, 0.2, 0.3)
        {
            Temperature = 25;
            Humidity = 50;
        }

        protected override void CreateMeasurement()
        {
            OnTemperatureMeasured();
            OnHumidityMeasured();
        }

        /// <summary>
        /// <see cref="ITemperatureHumidity.TemperatureMeasured"/>
        /// </summary>
        public event TemperatureMeasurementEventHandler TemperatureMeasured;

        protected void OnTemperatureMeasured()
        {
            var ev = TemperatureMeasured;
            if (ev != null)
            {
                ev(this, Temperature);
            }
        }

        /// <summary>
        /// <see cref="ITemperatureHumidity.HumidityMeasured"/>
        /// </summary>
        public event HumidityMeasurementEventHandler HumidityMeasured;

        protected void OnHumidityMeasured()
        {
            var ev = HumidityMeasured;
            if (ev != null)
            {
                ev(this, Humidity);
            }
        }
    }
}
